package com.jshoperxms.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.jshoperxms.controller.utils.statickey.TagWords;
import com.jshoperxms.dao.*;
import com.jshoperxms.entity.*;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.jshoperxms.controller.utils.enums.BaseEnums.DataUsingState;
import com.jshoperxms.service.OrderBaseProcessTService;
@Service("orderBaseProcessTService")
@Scope("prototype")
public class OrderBaseProcessTServiceImpl implements OrderBaseProcessTService {
	@Resource
	private MemberDeliverAddressTDao memberDeliverAddressTDao;
	@Resource
	private LogisticsBusinessTDao logisticsBusinessTDao;
	@Resource
	private PaymentTDao paymentTDao;
	@Resource
	private MemberCartTDao memberCartTDao;
	@Resource
	private LogisticsBusinessRegionPriceTDao logisticsBusinessRegionPriceTDao;
	@Resource
	private OrderTDao orderTDao;
	@Resource
	private OrderShippingAddressTDao orderShippingAddressTDao;
	@Override
	public List<MemberDeliverAddressT> findMemberDeliverAddressByMemberid(MemberT m) {
		Criterion criterion=Restrictions.eq("memberid", m.getId());
		return memberDeliverAddressTDao.findByCriteria(MemberDeliverAddressT.class, criterion);
	}


	@Override
	public List<LogisticsBusinessT> findLogisticstsBusiness(String usingway) {
		Map<String,Object>params=new HashMap<String,Object>();
		params.put(TagWords.STATUS, DataUsingState.USING.getState());
		params.put("usingway",usingway);
		Criterion criterion=Restrictions.allEq(params);
		return logisticsBusinessTDao.findByCriteria(LogisticsBusinessT.class, criterion);
	}


	@Override
	public List<PaymentT> findPayment() {
		Criterion criterion=Restrictions.eq(TagWords.STATUS, DataUsingState.USING.getState());
		return paymentTDao.findByCriteria(PaymentT.class, criterion);
	}


	@Override
	public List<MemberCartT> findMemberCart(String memberid, String status,String cartstatus,
			String orderTag) {
		Map<String,Object>params=new HashMap<String,Object>();
		params.put("memberid", memberid);
		params.put(TagWords.STATUS, status);
		params.put("cartstatus",cartstatus);
		params.put("orderTag", orderTag);
		Criterion criterion=Restrictions.allEq(params);
		return memberCartTDao.findByCriteria(MemberCartT.class, criterion);
	}




	@Override
	public PaymentT getSelectedPayMent(String paymentid) {
		return paymentTDao.findByPK(PaymentT.class, paymentid);
	}


	@Override
	public MemberDeliverAddressT getDeliverAddress(String addressid) {
		return memberDeliverAddressTDao.findByPK(MemberDeliverAddressT.class, addressid);
	}


	@Override
	public OrderT getOrder(String orderid) {
		return orderTDao.findByPK(OrderT.class, orderid);
	}


	@Override
	public OrderShippingAddressT getShippingAddress(String deliveraddressid,
			String status, String orderid) {
		Map<String,Object>params=new HashMap<String,Object>();
		params.put("deliveraddressid", deliveraddressid);
		params.put(TagWords.STATUS, status);
		params.put("orderid", orderid);
		Criterion criterion=Restrictions.allEq(params);
		return orderShippingAddressTDao.findOneByCriteria(OrderShippingAddressT.class, criterion);
	}


	@Override
	public List<OrderShippingAddressT> getShippingAddress(String orderid) {
		Criterion criterion=Restrictions.eq("orderid", orderid);
		return orderShippingAddressTDao.findByCriteria(OrderShippingAddressT.class, criterion);
	}

	@Override
	public MemberCartT getCurrentMemberCart(String goodsid, String productid, String memberid, String cartstatus, String cartactiontag, String promotioncometag, String storeid) {

		Map<String,Object>params=new HashMap<>();
		params.put("goodsid",goodsid);
		params.put("productid",productid);
		params.put("memberid",memberid);
		params.put("cartstatus",cartstatus);
		params.put("cartactiontag",cartactiontag);
		params.put("promotioncometag",promotioncometag);
		params.put("storeid",storeid);
		params.put(TagWords.STATUS,DataUsingState.USING.getState());
		Criterion criterion=Restrictions.allEq(params);
		return this.memberCartTDao.findOneByCriteria(MemberCartT.class,criterion);
	}


}
